﻿$(function () {
    $('#btnSearch').click(function () {
        search();
    });

    $('#btnAdd').click(function () {
        edit();
    });

    initTable();
});

//加载列表
function initTable() {
    $("#maingrid").ligerGrid({
        url: '/StrokeCenter/PathwaySet/Search?ram=' + Math.random(),
        columns: [
            { display: '节点名称', name: 'EventName', align: 'left', width: 220, editor: { type: "string" } }
            ,
            {
                display: '是否启用', name: 'IsDel', minWidth: 30, editor:{type:"string"}, render: function (row) {
                    return row.IsDel == 0 ? "是" : "否";
                }
            },
            { display: '排序', name: 'Sort', minWidth: 20, editor: { type: "string" } },
            {
                display: '操作', name: '', minWidth: 180, render: function (row) {
                    var dropdown = "<select style=\"height:22px\">";
                    //alert(row.BeforeEventNameList);
                    var jsonlist = window.JSON.parse(row.BeforeEventNameList);
                    if (jsonlist[0].name == undefined || jsonlist[0].name == 'undefined') {
                        dropdown += "<option value ='0'>无</option> ";
                    }
                    else {
                        for (var p in jsonlist) {
                            dropdown += "<option value ='" + jsonlist[p].eid + "'>" + jsonlist[p].name + "</option> ";
                        }
                    }
                    dropdown += "</select>";

                    if (row.ParentId == 0) {
                        return '<div style="heigth:100%;width:580px;text-align: left;margin:0px auto;"><a href="javascript:void(0);" onclick="EditContent(' + row.Id + ')">诊疗内容</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="del(' + row.Id + ')">删除</a></div>';
                    }
                    else {
                        return '<div style="heigth:100%;width:580px;text-align: left;margin:0px auto;">关联节点：' + dropdown + '&nbsp;&nbsp;&nbsp;&nbsp;时长：<input type="text" width="50" id="txtMinuts" style=\"width:55px;height:22px;text-align: center;\"/>分钟&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="edit(' + row.Id + ')">保存</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="del(' + row.Id + ')">删除</a></div>';
                    }
                }
            }
        ],
        enabledEdit: true,
        usePager: false,
        rownumbers: false,
        tree: {
            columnName: 'EventName',
            idField: 'Id',
            parentIDField: 'ParentId'
        },
        height: '100%',
        heightDiff: 25
    });
}

//搜索
function search() {
    $("#maingrid").ligerGrid().setParm("name", $("#txtName").val())
    $("#maingrid").ligerGrid().loadData();
}

//添加路径事件
function EditEvent(id) {
    $.ligerDialog.open({
        height: 200,
        width: 400,
        title: '添加路径事件节点',
        data: { Id: id },
        url: '/StrokeCenter/PathwaySet/EditEvent',        showMax: false,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        buttons: [{
            text: '回调函数', onclick: function (i, d) {
                $("#btnSearch").click();
            }
        }],
        cls: "closeCls"
    });
    $(".l-dialog-buttons").hide();
}
$(document).on("click", ".closeCls", function () {
    $("#btnSearch").click();
});
//诊疗内容操作
function EditContent(id)
{
    $.ligerDialog.open({
        height: 780,
        width: 1000,
        title: '诊疗内容',
        data: { Id: id },
        url: '/StrokeCenter/PathwaySet/EditContent',
        showMax: false,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        buttons: [{
            text: '回调函数', onclick: function (i, d) {
                $("#btnSearch").click();
            }
        }],
        cls: "closeCls"
    });
    $(".l-dialog-buttons").hide();
}
function del(id) { alert(id); }
function Back()
{
    window.history.go(-1);
}